package br.unesp.demac.ccn07.clientes.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import br.unesp.demac.ccn07.clientes.vo.Clientes;

public class ClientDAO extends Conexao {
	
	public ClientDAO()
			throws ClassNotFoundException, SQLException {
		
		super();	
	}
	
	public void insertClient(Clientes cli) throws SQLException {
		Statement stmt = conexao.createStatement();
		stmt.executeUpdate("insert into clientes (id, nome, email, telefone) values('"+
				cli.getId() +"' ,'" +
				cli.getNome() +"' ,'" +
				cli.getEmail() +"' ,'" +
				cli.getTelefone() +"')");
	}
	
	public Clientes getClientById(int id) throws SQLException {
		Clientes cli = new Clientes();

		Statement stmt = conexao.createStatement();
		ResultSet rs = stmt.executeQuery("select * from clientes where id = '"+ id +"'");
		
		cli.setId(id);
		cli.setNome(rs.getString("nome"));
		cli.setEmail(rs.getString("email"));
		cli.setTelefone(rs.getString("telefone"));

		return cli;	
	}
	
	public ResultSet clientsToTable() throws SQLException {
		Statement stmt = conexao.createStatement();
		ResultSet rs = stmt.executeQuery("select * from clientes");
		
		return rs;
	}

	
}
